<template>
    <rx-dialog @handOk="handOk" :oktext="$ti18('rxForm.closeBtn','关闭')" :showcancel="false">
        <rx-layout>
            <div slot="header">
                <div class="table-page-search-wrapper">
                    <a-form layout="inline">
                        <a-row :gutter="48">
                            <a-col :span="8">
                                <a-form-item :label="i18n('form.name','权限名称')">
                                    <a-input :placeholder="i18n('form.name','权限名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>

                            <a-col :span="8">
                              <span class="table-page-search-submitButtons">
                                <a-button type="primary" @click="loadData" icon="search">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                              </span>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
            </div>

            <div slot="center" style>
                <rx-grid
                    ref="table"
                    :allowRowSelect="false"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-system/system/core/sysAuthSetting/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                      <span slot="name" slot-scope="{ text, record }">
                          {{$i18(text, '权限名称')}}
                      </span>
                      <span slot="category" slot-scope="{ text, record }" :title="getRightName(record)">
                          {{ getRightName(record) }}
                      </span>
                      <span slot="enable" slot-scope="{text,record,index}" >
                           <a-tag :color="statusMap[text].color">
                            <span>{{statusMap[text].text}}</span>
                          </a-tag>
                      </span>
                      <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click.stop="editAuthSetting(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                      </span>
                </rx-grid>

            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>
    import SysAuthSettingApi from '@/api/system/core/sysAuthSetting'
    import {BaseList, RxLayout, Util} from "@lowcode/jpaas-common-lib"
    import SysAuthSettingEdit from "./SysAuthSettingEdit";

    export default {
        name: 'SysAuthSettingDialog',
        mixins: [BaseList],
        components: {
            RxLayout
        },
        props: {
            layerid: {
                type: String,
                default: ""
            },
            destroy: {
                type: Function
            },
            catKey: {
                type:String,
                default: ""
            }
        },
        data() {
            return {
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type: 'indexColumn',
                        width: 100,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'}
                    },
                    {title: this.i18n('form.name','权限名称'), dataIndex: 'name', width: 100,scopedSlots: {customRender: 'name'}},
                    {title: this.i18n('form.category','所属分类'), dataIndex: 'category',scopedSlots: {customRender: 'category'}, width: 100},
                    {title: this.i18n('form.enabled','是否启用'), dataIndex: 'enable',scopedSlots: {customRender: 'enable'}, width: 100},
                    {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', width: 100},
                    {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
                ],
                component:SysAuthSettingEdit,
                comment:this.i18n('list.comment','权限配置表'),
                widthHeight:['800px','600px'],
                statusMap: {
                    "true": {color: 'green', text: this.i18n('form.enable','启用')},
                    "false": {color: 'red', text: this.i18n('form.disable','停用')}
                }
            }

        },
        created() {
            this.queryParam.Q_TYPE__S_EQ=this.catKey;
            this.needFilterAppId();
        },
        methods: {
            i18n(name,text,key){
                return this.$ti18(name,text,"SysAuthSetting",key);
            },
            delById(ids){
                return SysAuthSettingApi.del({ ids: ids.join(',') });
            },
            editAuthSetting(record){
                var conf={
                    pkId:record.pkId,
                    component:this.component,
                    title:this.$ti18('rxList.editBtn','编辑') + this.comment,
                    widthHeight:this.widthHeight,
                    data:{pkId:record.pkId,type:record.type}
                };
                this.handleEdit(conf);
            },
            handOk() {
                Util.closeWindow(this, "ok");
            },
            getRightName(record){
                if (!record.sysAuthRights){
                    return ""
                }
                var sysAuthRights=record.sysAuthRights;
                var rightName="";
                for (let sysAuthRight of sysAuthRights){
                    rightName+=this.$i18(sysAuthRight.treeName)+","
                }
                //去除最后的 ，
                rightName=(rightName.length>0?rightName.substring(0,rightName.length-1):"")
                return rightName;
            }
        }
    }
</script>
<style scoped>

</style>

